unit Gen;

interface

uses
  Windows, SysUtils, Math, StrUtils, Clipbrd, CnMD5;

function calcReginsterCode(key:string):string;
function checkCondition(k26,k28,k30:Char):Integer;  
procedure SetClipboard(s:string);

implementation

procedure SetClipboard(s:string);
begin
  if s='' then Exit;
  with TClipboard.Create do
  begin
    AsText:=s;
    Free;
  end;
end;

function calcReginsterCode(key:string):string;
const
  suffix='windows-';
  odd='22200ce06b66a';
  codeLen=32;
var
  flip_key,md5:string;
  code32:array [0..codeLen-1] of Char;
  i,keyLen:Integer;
begin
  Result:='';
  
  FillChar(code32,codeLen,#0);
  for i:=1 to Length(odd) do
    code32[(i-1)*2]:=odd[i];

  keyLen:=Length(key);
  flip_key:='';
  for i:=0 to keyLen-1 do
    flip_key:=flip_key+key[keyLen-i];

  md5:=MD5Print(MD5String(flip_key)); 
  for i:=0 to 7 do
  begin
    code32[i*4+1]:=md5[i*2+1];
    code32[i*4+3]:=md5[i*2+2];
  end;
  //windows-2421220b07c2e10a6eb96768a2p7r6gc
  //windows-2421220b07c2e10a6eb96768a2o7p6hc

  code32[26]:=Chr($70);
  code32[28]:=Chr($72);
  code32[30]:=Chr($67);
  if checkCondition(code32[26],code32[28],code32[30])=-1 then Exit;
  Result:=suffix+string(code32);
end;

function checkCondition(k26,k28,k30:Char):Integer;
begin 
  Result:=-1;
  if (Ord(k28)+Ord(k30)-$69=Ord(k26)) and (Ord(k28)>=$63) and (Ord(k28)<>$65) then
  begin
    if (Ord(k28)<>$66) or (Ord(k30)>=$6C) then Result:=0;
  end;
end;

end.
